package sctu.edu.java.year2016.team06.project;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Scanner;

/**
 * Created by LCJ on 2016/6/22.
 */
public class Worker extends Database {
    Scanner scan = new Scanner(System.in);

    public void specfic() throws IOException {

        String specfic;

        System.out.println("请您输入这个问题的一些具体情况：");
        specfic = scan.nextLine();

        File file = new File("D:/userwrite.txt");
        file.createNewFile();

        DefineFileOutputStream fileOutputStream = new DefineFileOutputStream(file);
        fileOutputStream.write(specfic);
        fileOutputStream.close();
    }


    public void methed() throws IOException {

        Database fil = new Database();

        fil.Document();                       //调用自创数据库Database的Document()方法

    }


    public void methed1() throws IOException {


        FileInputStream fileInputStream = new FileInputStream("D:/workerwrite.txt");
        byte byt[] = new byte[10000];
        int length = fileInputStream.read(byt);
        System.out.println("解决方案如下：\n" + new String(byt, 0, length));
        fileInputStream.close();


    }


    public void methed2() throws IOException {
        File file = new File("D:/communication.txt");
        String updata;
        updata = scan.nextLine();
        DefineFileOutputStream fileOutputStream = new DefineFileOutputStream(file);
        fileOutputStream.write(updata);
        fileOutputStream.close();


    }


    public static void main(String[] args) throws IOException {
        Scanner scan = new Scanner(System.in);
        Worker member = new Worker();

        System.out.println("欢迎进入工作界面！");

        System.out.println("★★★★★★★★★★★★★★★★★★★★★★★★★★★★");
        System.out.println("★1.在线服务平台★2.维护数据库★3.平台论坛★4.退出平台★");
        System.out.println("★★★★★★★★★★★★★★★★★★★★★★★★★★★★");
        System.out.println("请输入功能前的数字：");
        int i = 0;
        while (i < 10000) {

            int j;

            j = scan.nextInt();
            switch (j) {

                case 1:
                    FileInputStream fileInputStream = new FileInputStream("D:/userwrite.txt");
                    byte byt[] = new byte[10000];
                    int length = fileInputStream.read(byt);
                    System.out.println("客户的情况如下：\n" + new String(byt, 0, length));
                    fileInputStream.close();
                    member.methed();                             //调用成员方法methed()方法，功能：将信息输入。
                    System.out.println("您已完成工作，请输入一些提示信息告诉用户：");
                    member.methed2();                           //调用成员方法methed2()方法，功能：给用户回复提示信息。
                    Database sever = new Database();
                    sever.questionbase();
                    sever.Document1();                     //调用成员方法Document1()方法，功能：将已解决的问题写入自创数据库Database。
                    System.out.println("正在上传数据，请稍后！");
                    MyThread myThread=new MyThread();
                    myThread.run();
                    System.out.println("\n");
                    System.out.println("您的数据已录入数据库。");
                    String sun;
                    System.out.println("你是否查看数据库？");
                    sun=scan.next();
                    if(sun.equals("是"))
                        sever.Document2();
                    break;
                case 4:
                    String back;
                    System.out.println("系统提示：请输入“是”或者“否”");
                    System.out.println("您是否要退出工作平台？");
                    back=scan.next();
                    if(back.equals("是")) {
                        System.out.println("您已成功退出平台!");
                        System.exit(0);
                    }
                    break;
                case 2:
                    Database sever1 = new Database();
                    sever1.questionbase();
                    sever1.Document1();                     //调用成员方法Document1()方法，功能：将已解决的问题写入自创数据库Database。
                    System.out.println("正在上传数据，请稍后！");
                    MyThread myThread1=new MyThread();
                    myThread1.run();
                    System.out.println("\n");
                    System.out.println("您的数据已录入数据库。");
                    String sun1;
                    System.out.println("你是否查看数据库？");
                    sun1=scan.next();
                    if(sun1.equals("是"))
                        sever1.Document2();
                    break;
                case 3:
                    Database sever2 = new Database();
                    int w;
                    System.out.println("★★★★★★★★★★★★★★");
                    System.out.println("★1.发表留言★2.查看留言板★");
                    System.out.println("★★★★★★★★★★★★★★");
                    System.out.println("请输入功能前的数字：");
                    w=scan.nextInt();
                    if(w==1) {
                        sever2.meassage();
                    }
                    else if(w==2) {
                        sever2.meassage1();
                    }
                    else {
                        System.out.println("输入错误！");
                    }
                    break;

                default:
                    System.out.println("输入错误，请重新输入！");
            }
            i++;
            System.out.println("★★★★★★★★★★★★★★★★★★★★★★★★★★★★★");
            System.out.println("★1.在线服务平台★2.维护数据库★★3.平台论坛★4.退出平台★");
            System.out.println("★★★★★★★★★★★★★★★★★★★★★★★★★★★★★");
            System.out.println("请输入功能前的数字：");
        }
    }
}
